package com.woniuxy.service.impl;

import org.springframework.cglib.proxy.Callback;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;

//代理类
public class CatPro {
    public Object createProxyObject(Object obj){
        Object o = Enhancer.create(obj.getClass(), new MethodInterceptor() {
            @Override
            public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                //前置方法
                System.out.println("前置");
                //这种写法不用去记忆
                Object o1 = methodProxy.invokeSuper(o, objects);
                //后置方法
                System.out.println("后置");
                return o1;
            }
        });
        return o;
    }
}
